﻿/****************************************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
	Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using System.Security.Principal;

namespace BaoJianSoft.Platform
{
	/// <summary>
	/// The interface of role accessing
	/// </summary>
	public interface IRoleApi
	{
		/// <summary>
		/// Save role business object. 
		/// It does create/update based on roleObject.Id. If id is empty, the method will create a new role object.
		/// If the specified id is invalid, the method will throw an exception.
		/// </summary>
		/// <param name="roleObject">role object</param>
		void Save(RoleObject roleObject);

		/// <summary>
		/// Delete role
		/// </summary>
		/// <param name="roleId"></param>
		void Delete(Guid roleId);

		/// <summary>
		/// Set user into roles which overwrites all existed roles of user.
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="roleIds"></param>
		void SetUserToRoles(Guid userId, IEnumerable<Guid> roleIds);

		/// <summary>
		/// Get role id by role name.
		/// </summary>
		/// <param name="roleName"></param>
		/// <returns></returns>
		RoleObject Get(string roleName);

		/// <summary>
		/// Get role id by role id.
		/// </summary>
		/// <param name="roleId"></param>
		/// <returns></returns>
		RoleObject Get(Guid roleId);

		/// <summary>
		/// Bulkget role objects by a collection of role ids.
		/// </summary>
		/// <param name="roleIds"></param>
		/// <returns></returns>
		IDictionary<Guid, RoleObject> BulkGet(IEnumerable<Guid> roleIds);

		/// <summary>
		/// Find all available roles.
		/// </summary>
		/// <returns></returns>
		IEnumerable<RoleObject> FindAll();

		/// <summary>
		/// Find roles by enumerable organization type ids. returns all if specified argument is null.
		/// </summary>
		/// <param name="organizationTypeIdList">enumerable organization type ids</param>
		/// <returns></returns>
		IEnumerable<RoleObject> FindByOrganizationTypes(IEnumerable<Guid> organizationTypeIdList);

		/// <summary>
		/// Find all roles of specified user.
		/// </summary>
		/// <param name="userId"></param>
		/// <returns></returns>
		IEnumerable<RoleObject> FindByUserId(Guid userId);

		/// <summary>
		/// Gets true if specified user is in role.
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="roleId"></param>
		/// <returns></returns>
		bool IsUserInRole(Guid userId, Guid roleId);

		/// <summary>
		/// Gets true if specified user is in role.
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="roleName"></param>
		/// <returns></returns>
		bool IsUserInRole(Guid userId, string roleName);
	}
}

